package com.example.bookmanager_back.entity.vo;

import com.alibaba.fastjson2.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Result<T> {
    private int status;
    private String msg;
    private T data;

    public String toJsonString(){
        return JSONObject.toJSONString(this);
    }

    public static<T> Result<T> success(T data){
        return new Result<>(200, "后端服务器响应成功", data);
    }

    public static<T> Result<T> failure() { return new Result<>(415, "请求格式错误", null); }

    public static<T> Result<T> error() { return new Result<>(500, "后端服务器异常", null); }
}
